﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CDStore3Tiers;

namespace CuaHangDiaNhac
{
    public partial class frmDanhSachDiaNhac : DevComponents.DotNetBar.Office2007Form
    {
        StoreCDDataContext db = new StoreCDDataContext();
        XuLyBaiHat XLBH = new XuLyBaiHat();
        DataGridViewTextBoxColumn coMaDia;
        DataGridViewTextBoxColumn coTenDia;
        DataGridViewTextBoxColumn coLoaiDia;
        DataGridViewTextBoxColumn coMaBH;
        public void LoadDS(List<vwDSDiaNhac> a)
        {
            //var dsdn = db.vwDSDiaNhacs;
            BindingSource ddn = new BindingSource();
            ddn.DataSource = a;
            bindingNavigator1.BindingSource = ddn;
            dgvDS.DataSource = ddn;
        }
        public void loadDGV(List<vwDSDiaNhac> a)
        {
            dgvDS.DataSource = null;  
            //dgvDS.DataSource = a;
                      
            coMaDia = new DataGridViewTextBoxColumn();
            //coMaDia.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            coMaDia.DataPropertyName = "MaDia";
            coMaDia.HeaderText = "Mã đĩa nhạc";
            coMaDia.Name = "cMaDia";
            coMaDia.Visible = false;
            dgvDS.Columns.Add(coMaDia);


            coTenDia = new DataGridViewTextBoxColumn();
            coTenDia.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            coTenDia.DataPropertyName = "TenDia";
            coTenDia.HeaderText = "Tên đĩa nhạc";
            coTenDia.Name = "cTenDia";
            dgvDS.Columns.Add(coTenDia);


            coLoaiDia = new DataGridViewTextBoxColumn();
            coLoaiDia.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            coLoaiDia.DataPropertyName = "TenLoai";
            coLoaiDia.HeaderText = "Loại đĩa";
            coLoaiDia.Name = "cTenLoai";
            dgvDS.Columns.Add(coLoaiDia);

            coMaBH = new DataGridViewTextBoxColumn();
            //coLoaiDia.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            coMaBH.DataPropertyName = "MaBH";
            coMaBH.Name = "cMaBH";
            coMaBH.Visible = false;
            dgvDS.Columns.Add(coMaBH);

            LoadDS(a);
        }
        public frmDanhSachDiaNhac(int maso)
        {
            InitializeComponent();
            Getdata(maso);
        }

        public void Getdata(int maso)
        {

            try
            {
                var dn = db.BaiHat_DiaNhac_SelectByID1(maso);
                if (dn != null)
                {
                    List<vwDSDiaNhac> ct = XLBH.GetDSDN(maso) ;
                    dgvDS.DataSource = ct;
                    loadDGV(ct);
                }
            }
            catch (Exception)
            {
                dgvDS.DataSource = null;
            }
        }

        private void dgvDS_DataSourceChanged(object sender, EventArgs e)
        {
        }

        private void frmDanhSachDiaNhac_Load(object sender, EventArgs e)
        {
        }

        private void frmDanhSachDiaNhac_Activated(object sender, EventArgs e)
        {
            if (this.Owner != null)
            {
                this.Owner.Enabled = false;
            }
        }

        private void frmDanhSachDiaNhac_Deactivate(object sender, EventArgs e)
        {
            if (this.Owner != null)
            {
                this.Owner.Enabled = true;
            }
        }

    }
}
